package momo.multitree.algo;

import momo.multitree.structure.*;

import java.util.LinkedHashSet;

import junit.framework.TestCase;


public class CostDijkstraTest extends TestCase {

	public void testCalObjCost()
	{
		CostDijkstra app = new CostDijkstra();
		Node root = new Node("1", 0.5, 0.6); //root node
		Node node2 = new Node("2", 0.1, 0.3);
		Node node3 = new Node("3", 0.1, 0.8);
		Node node4 = new Node("4", 0.1, 0.4);
		Node node5 = new Node("5", 0.2, 0.9);
		
		Edge edge1 = new Edge("1", root, node2, 5, 2, 6, 6);
		Edge edge2 = new Edge("2", root, node3, 4, 3, 3, 3);
		Edge edge3 = new Edge("3", node2, node4, 1, 7, 2, 2);
		Edge edge4 = new Edge("4", node2, node5, 10, 0, 1, 1);
		
		LinkedHashSet<Node> S = new LinkedHashSet<Node>();
		LinkedHashSet<Edge> Et = new LinkedHashSet<Edge>();
		
		S.add(root);
		assertEquals(4.7, app.calObjCost(S, node2, Et, edge1, null), 0.00000001);
		
		S.add(node2);
		Et.add(edge1);
		assertEquals(8.6, app.calObjCost(S, node3, Et, edge2, null), 0.00000001);
		
		S.add(node3);
		Et.add(edge2);
		assertEquals(10.9, app.calObjCost(S, node4, Et, edge3, null), 0.00000001);
		
		S.add(node4);
		Et.add(edge3);
		assertEquals(19.3, app.calObjCost(S, node5, Et, edge4, null), 0.00000001);
	}

	public void testOneOptimumTree()
	{
		Node node1 = new Node("1", 0.3, 1);
		Node node2 = new Node("2", 0.2, 1);
		Node node3 = new Node("3", 0.1, 1);
		Node node4 = new Node("4", 0.1, 1);
		Node node5 = new Node("5", 0.2, 1);
		Node node6 = new Node("6", 0.1, 1);
		
		Edge edge1 = new Edge("1", node1, node2, 5, 2, 3, 3);
		Edge edge2 = new Edge("2", node1, node3, 4, 3, 2, 2);
		Edge edge3 = new Edge("3", node2, node3, 5, 2, 1, 1);
		Edge edge4 = new Edge("4", node2, node5, 10, 0, 2, 2);
		Edge edge5 = new Edge("5", node3, node5, 1, 3, 4, 4);
		Edge edge6 = new Edge("6", node3, node6, 4, 2, 6, 6);
		Edge edge7 = new Edge("7", node6, node5, 6, 5, 2, 2);
		Edge edge8 = new Edge("8", node4, node5, 7, 1, 1, 1);
		Edge edge9 = new Edge("9", node2, node4, 1, 7, 4, 4);
		
		Graph graph = new Graph();
		graph.add(edge1);
		graph.add(edge2);
		graph.add(edge3);
		graph.add(edge4);
		graph.add(edge5);
		graph.add(edge6);
		graph.add(edge7);
		graph.add(edge8);
		graph.add(edge9);
		
		CostDijkstra app = new CostDijkstra();
		Tree tree1 = app.optimumTree(graph, node1);
		
		Tree tree2 = new Tree(node1);
		tree2.add(edge2);
		tree2.add(edge5);
		tree2.add(edge8);
		tree2.add(edge3);
		tree2.add(edge6);
		
		assertTrue(tree2.compare(tree1));
	}

}
